package ys.mihoyo.ymcc.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ys.mihoyo.ymcc.result.JSONResult;
import ys.mihoyo.ymcc.dto.SendSmsParamDto;
import ys.mihoyo.ymcc.service.VerifyCodeService;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     * @param key 前端传入的key，作为redis的key
     * @return
     */
    @GetMapping("/imageCode/{key}")
    public JSONResult getImageCode(@PathVariable("key") String key) {
        String base64Str = verifyCodeService.getImgCode(key);
        return JSONResult.success(base64Str);
    }

    /**
     * 获取短信验证码
     */
    @PostMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody @Valid SendSmsParamDto sendSmsParamDto){
        verifyCodeService.sendSmsCode(sendSmsParamDto);
        return JSONResult.success();
    }
}
